package com.yiyang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yiyang.domain.po.Bed;
import com.yiyang.domain.po.Room;
import com.yiyang.domain.vo.RoomVo;
import com.yiyang.mapper.BedMapper;
import com.yiyang.service.RoomService;
import com.yiyang.mapper.RoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 31044
* @description 针对表【room】的数据库操作Service实现
* @createDate 2024-09-28 15:04:24
*/
@Service
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room>
    implements RoomService{

    @Autowired
    private BedMapper bedMapper;
    @Override
    public RoomVo findCwsyBedVo(String floor) {
        List<Room> roomList = lambdaQuery().eq(Room::getRoomfloor, floor).list();

        RoomVo roomVo = new RoomVo();
        roomVo.setRoomList(roomList);

        for (Room room : roomList) {
            //根据房号查询床位
            List<Bed> bedList = bedMapper.selectList(new LambdaQueryWrapper<Bed>().eq(Bed::getRoomNo, room.getRoomNo()));

            room.setBedList(bedList);
            //总床位数
            roomVo.setZcw(roomVo.getZcw() + bedList.size());

            for (Bed bed : bedList) {
                if (bed.getStatus() == 1){
                    roomVo.setKx(roomVo.getKx() + 1);
                }else if (bed.getStatus() == 2){
                    roomVo.setYr(roomVo.getYr() + 1);
                }else {
                    roomVo.setWc(roomVo.getWc() + 1);
                }
            }
        }

        return roomVo;
    }
}